package com.yueqian.web.controller;

import com.yueqian.pojo.User;
import com.yueqian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("login")
    public String login(User user, HttpSession session) {
        User logedUser = userService.login(user);
        if (logedUser == null) {
            //登录失败
            //return "fail";
            return "forward:/login.jsp";
        } else {
            //登录成功,将登录的用户信息存入到session
            session.setAttribute("logedUser", logedUser);
            return "success";
        }
    }
}
